﻿<UserControl x:Class="Mido.UiModules.SettingsModule.SettingsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Controls="clr-namespace:Mido.Controls"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:SettingsModule="clr-namespace:Mido.UiModules.SettingsModule"
             xmlns:Properties="clr-namespace:Mido.Properties"
             xml:lang="en-US"
             Background="Transparent"
             BorderThickness="1,1,0,0"
             d:DataContext="{x:Static SettingsModule:SettingsViewModel.Designer}"
             Padding="5"
             mc:Ignorable="d" d:Height="442">
    <UserControl.Resources>
        <ControlTemplate x:Key="HeaderedControlTemplate" TargetType="HeaderedContentControl">
            <DockPanel>
                <!--Header-->
                <Grid DockPanel.Dock="Top" Height="20">
                    <Border Background="{StaticResource DefaultAppBrush}">
                        <ContentPresenter ContentSource="Header" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    </Border>
                </Grid>
                <!--Content-->
                <Grid>
                    <ContentPresenter ContentSource="Content" Margin="5"/>
                </Grid>
            </DockPanel>
        </ControlTemplate>
    </UserControl.Resources>

    <StackPanel Grid.IsSharedSizeScope="True">

        <GroupBox Header="{x:Static Properties:Resources.SettingsView_General}" Template="{StaticResource HeaderedControlTemplate}">
            <Grid>
                <Grid.Resources>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="Margin" Value="0,0,0,2" />
                    </Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>
                </Grid.Resources>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="title"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Text="{x:Static Properties:Resources.SettingsView_Content__}" VerticalAlignment="Center"/>
                <ComboBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" ItemsSource="{Binding PossibleContentTypes}" SelectedValue="{Binding ContentType, Mode=TwoWay}" Margin="0,1,0,1"
                          DisplayMemberPath="Value" SelectedValuePath="Key"/>

                <TextBlock Grid.Row="1" Text="{x:Static Properties:Resources.SettingsView_Location__}" VerticalAlignment="Center"/>
                <ComboBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding PossibleSides}" SelectedValue="{Binding Side, Mode=TwoWay}" Margin="0,1,0,1"
						  DisplayMemberPath="Item2" SelectedValuePath="Item1">
                    <ComboBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel IsItemsHost="True" ItemWidth="100" Width="300"/>
                        </ItemsPanelTemplate>
                    </ComboBox.ItemsPanel>
                </ComboBox>

                <TextBlock Grid.Row="2" Text="{x:Static Properties:Resources.SettingsView_Angle}" VerticalAlignment="Center"/>
                <ComboBox Grid.Row="2" Grid.Column="1" ItemsSource="{Binding PossibleWatermarkAngle}" SelectedItem="{Binding WatermarkAngle, Mode=TwoWay}" Margin="0,1,0,1"/>

                <TextBlock Text="{Binding OpacityTitle}" Grid.Row="3" VerticalAlignment="Center"/>
                <Slider Grid.Row="3" Grid.Column="1" Value="{Binding Opacity}" Maximum="100" Minimum="0"/>
            </Grid>
        </GroupBox>

        <GroupBox Header="{x:Static Properties:Resources.SettingsView_Text}" Visibility="{Binding TextEditorVisibility}" Template="{StaticResource HeaderedControlTemplate}">
            <Grid>
                <Grid.Resources>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="Margin" Value="0,0,0,2" />
                    </Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>
                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="title"/>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="107*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Row="1" Text="{x:Static Properties:Resources.SettingsView_Text__}" Margin="0,9" />
                <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontFamily="{Binding FontName}"
                             AcceptsReturn="True" TextAlignment="{Binding TextEditorAligment}"/>

                <TextBlock Grid.Row="2" Text="{x:Static Properties:Resources.SettingsView_Aligment__}" Visibility="{Binding TextAlignmentVisibility}" Margin="0,4"/>
                <ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" SelectedValue="{Binding TextAlignment, Mode=TwoWay}" ItemsSource="{Binding AllTextAlignment}" Visibility="{Binding TextAlignmentVisibility}"
                          DisplayMemberPath="Value" SelectedValuePath="Key" Margin="0,1,0,1"/>

                <TextBlock Grid.Row="3" Text="{x:Static Properties:Resources.SettingsView_Font__}" Margin="0,4" />
                <Grid Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <ComboBox Grid.Column="0" SelectedItem="{Binding FontName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{x:Static Fonts.SystemFontFamilies}" Margin="0,1,1,1"
                              FontFamily="{Binding FontName, Mode=OneWay}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" FontFamily="{Binding}"/>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                    <ToggleButton Height="22" Width="22" Grid.Column="1" IsChecked="{Binding IsBold}" VerticalContentAlignment="Center" Margin="1,1,1,1">
                        <Path Fill="Black" Stretch="Fill" Data="M34.854,26.895c1.614,0.469,2.864,1.335,3.75,2.598c0.885,1.264,1.328,2.812,1.328,4.648 c0,2.812-0.951,4.909-2.852,6.289c-1.901,1.381-4.792,2.07-8.672,2.07h-12.48V13.34h11.289c4.049,0,6.982,0.612,8.799,1.836 c1.816,1.224,2.725,3.184,2.725,5.879c0,1.419-0.332,2.627-0.996,3.623S36.116,26.413,34.854,26.895z M27.607,24.629 c1.185,0,2.083-0.26,2.695-0.781c0.611-0.521,0.918-1.289,0.918-2.305c0-1.002-0.307-1.768-0.918-2.295 c-0.612-0.527-1.511-0.791-2.695-0.791h-4.16v6.172H27.607z M27.861,37.383c1.51,0,2.646-0.318,3.408-0.957 c0.762-0.638,1.143-1.602,1.143-2.891c0-1.263-0.378-2.21-1.133-2.842c-0.756-0.631-1.895-0.947-3.418-0.947h-4.414v7.637H27.861z "/>
                    </ToggleButton>
                    <ToggleButton Height="22" Width="22" Grid.Column="2" IsChecked="{Binding IsItalic}" VerticalContentAlignment="Center" Margin="1,1,1,1">
                        <Path Fill="Black" Stretch="Fill" Data="M22.217,13.34h16.211l-0.645,3.32H31.65l-4.355,22.52h6.133l-0.645,3.32H16.572l0.645-3.32h6.113 l4.375-22.52h-6.133L22.217,13.34z "/>
                    </ToggleButton>
                    <ToggleButton Height="22" Width="22" Grid.Column="3" IsChecked="{Binding IsUnderline}" VerticalContentAlignment="Center" Margin="1,1,1,1">
                        <Image>
                            <Image.Source>
                                <DrawingImage>
                                    <DrawingImage.Drawing>
                                        <DrawingGroup>
                                            <GeometryDrawing Brush="Black" Geometry="M16.338,13.34h3.965v17.715c0,3.125,0.566,5.375,1.699,6.748c1.133,1.374,2.969,2.061,5.508,2.061 c2.525,0,4.355-0.687,5.488-2.061c1.133-1.373,1.699-3.623,1.699-6.748V13.34h3.965v18.203c0,3.803-0.941,6.674-2.822,8.613 c-1.882,1.94-4.658,2.91-8.33,2.91c-3.685,0-6.468-0.97-8.35-2.91c-1.882-1.939-2.822-4.811-2.822-8.613V13.34z " />
                                            <GeometryDrawing Brush="Black" Geometry="M12.861,48.057v-2.793h29.277v2.793H12.861z" />
                                        </DrawingGroup>
                                    </DrawingImage.Drawing>
                                </DrawingImage>
                            </Image.Source>
                        </Image>
                    </ToggleButton>
                </Grid>

                <TextBlock Grid.Row="4" Text="{x:Static Properties:Resources.SettingsView_Font_Size__}" Margin="0,1" />
                <TextBox Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding FontSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Stretch" Margin="0,1,1,1"/>
                <ComboBox Grid.Row="4" Grid.Column="3" ItemsSource="{Binding AllFontSizeTypes}" SelectedValue="{Binding FontSizeType, Mode=TwoWay}" Margin="1,1,0,1"
                          DisplayMemberPath="Value" SelectedValuePath="Key"/>

                <TextBlock Grid.Row="5" Text="{x:Static Properties:Resources.SettingsView_Color__}" Margin="0,4" />
                <ComboBox Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="3" SelectedItem="{Binding Color, Mode=TwoWay}" ItemsSource="{x:Static SettingsModule:ColorDefinition.AllColors}" Margin="0,1,0,1">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Rectangle Grid.Column="0" Width="15" Height="15" Stretch="Fill" Stroke="Black" RadiusX="3" RadiusY="3" VerticalAlignment="Center">
                                    <Rectangle.Fill>
                                        <SolidColorBrush Color="{Binding Color}"/>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <TextBlock Grid.Column="1" Text="{Binding Name}" Margin="3,0,0,0" VerticalAlignment="Center"/>
                            </Grid>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <TextBlock Grid.Row="6" Text="{x:Static Properties:Resources.SettingsView_Stroke__}" Margin="0,4" />
                <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding StrokeWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="30" VerticalAlignment="Stretch" Margin="0,1,1,1"/>
                <ComboBox Grid.Row="6" x:Name="cmbStroke" Grid.Column="2" SelectedItem="{Binding Stroke, Mode=TwoWay}" ItemsSource="{x:Static SettingsModule:ColorDefinition.AllColors}" Grid.ColumnSpan="2" Margin="1,1,0,1">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Rectangle Grid.Column="0" Width="15" Height="15" Stretch="Fill" Stroke="Black" RadiusX="3" RadiusY="3" VerticalAlignment="Center">
                                    <Rectangle.Fill>
                                        <SolidColorBrush Color="{Binding Color}"/>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <TextBlock Grid.Column="1" Text="{Binding Name}" Margin="3,0,0,0" VerticalAlignment="Center"/>
                            </Grid>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </Grid>
        </GroupBox>

        <GroupBox Header="{x:Static Properties:Resources.SettingsView_Image}" Visibility="{Binding ImageEditorVisibility}" Template="{StaticResource HeaderedControlTemplate}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="title"/>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <TextBlock Text="{x:Static Properties:Resources.SettingsView_Image__}" VerticalAlignment="Center"/>

                <TextBlock Grid.Column="1" Grid.ColumnSpan="2" VerticalAlignment="Center">
                    <Hyperlink Command="{Binding OpenWatermarkImageCommand}" ToolTip="{Binding ImagePath, Mode=OneWay}">
                        <Run Text="{Binding ImageFileName, Mode=OneWay}" />
                    </Hyperlink>
                </TextBlock>

                <TextBlock Grid.Row="1" Text="{x:Static Properties:Resources.SettingsView_Relative_Size__}" VerticalAlignment="Center"/>
                <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding RelativeImageSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Stretch" Margin="0,1,1,1"/>
                <ComboBox Grid.Row="1" Grid.Column="2" ItemsSource="{Binding AllFontSizeTypes}" SelectedValue="{Binding ImageSizeType, Mode=TwoWay}" VerticalAlignment="Center" Margin="1,1,0,1"
                          DisplayMemberPath="Value" SelectedValuePath="Key"/>
                
            </Grid>
        </GroupBox>

        <GroupBox Header="{x:Static Properties:Resources.SettingsView_Resizing}" Template="{StaticResource HeaderedControlTemplate}">
            <Grid>
                <Grid.Resources>
                    <Style TargetType="{x:Type TextBox}">
                        <Setter Property="Margin" Value="0,0,0,2" />
                    </Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>
                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="title"/>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <CheckBox Grid.Row="0" Grid.ColumnSpan="2" Content="{x:Static Properties:Resources.SettingsView_Keep_Original_Size}" IsChecked="{Binding KeepOriginalSize, Mode=TwoWay}" />

                <TextBlock Grid.Row="1" Text="{x:Static Properties:Resources.SettingsView_Max_Width__}" Visibility="{Binding ResizeOptionsVisibility}"/>
                <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding MaxWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding ResizeOptionsVisibility}"/>

                <TextBlock Grid.Row="2" Text="{x:Static Properties:Resources.SettingsView_Max_Height__}" Visibility="{Binding ResizeOptionsVisibility}"/>
                <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding MaxHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding ResizeOptionsVisibility}"/>

            </Grid>
        </GroupBox>
    </StackPanel>
</UserControl>
